const { createApp } = Vue;

createApp({
    data() {
        return {
            username: '',
            password: '',
            errorMessage: ''
        };
    },
    methods: {
        login() {
            if (this.username === 'admin' && this.password === 'admin') {
                this.errorMessage = '';
                // 登录成功后跳转到index.html
                const loginTime = new Date().toLocaleString(); // 获取当前时间
                const loginLocation = "登录地点: 系统"; // 可以根据需要修改
                const loginMessage = `欢迎登录，管理员！！\n登录时间: ${loginTime}\n${loginLocation}`;
                console.log(loginMessage);
                localStorage.setItem('loginMessage', loginMessage); // 存储消息
                localStorage.setItem('authToken', '生成的令牌');
                localStorage.setItem('userData', JSON.stringify({
                    id: 1001,
                    name: 'admin'
                }));
                const urlParams = new URLSearchParams(window.location.search);
                window.location.href = urlParams.get('redirect') || 'index.html';
            } else {
                this.errorMessage = '用户名或密码错误！';
            }
        }
    },
    mounted() {
        // 页面加载完成后，添加动画类
        this.$nextTick(() => {
            const loginContainer = document.querySelector('.login-container');
            if (loginContainer) {
                loginContainer.classList.add('animate');
            }
        });
    }
}).mount('#app');